package com.matrix.java.chap_05;

import java.util.Scanner;

/*
    财务应用程序：比较不同利率下的贷款
 */
public class Ex5_21 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Loan Amount: ");
        double amount = input.nextDouble();
        System.out.print("Number of Years: ");
        int year = input.nextInt();
        double monthPayment;
        double totalPayment;
        System.out.println("Interest Rate   Monthly Payment   Total Payment");
        for (double yearRate = 0.05; yearRate <= 0.081; yearRate += 0.00125) {
            double monthRate = yearRate / 12;
            monthPayment = (amount * monthRate) / (1 - (1 / Math.pow(1 + monthRate, year * 12)));
            totalPayment = monthPayment * year * 12;
            System.out.printf("%.3f%%%s%.2f%s%.2f%n", yearRate * 100, "          ", monthPayment, "            ", totalPayment);
        }
        input.close();
    }
}
